import express from 'express'
import userService from '../controllers/user/users.js'
const router = express.Router()

/* GET users listing. */
router.post('/login', authenticate);
router.get('/', getAll);

function authenticate(req, res, next) {
  userService.authenticate(req.body)
      .then(user => res.json(user))
      .catch(next);
}

function getAll(req, res, next) {
  userService.getAll()
      .then(users => res.json(users))
      .catch(next);
}

export default router
